package com.gs.SynAntiWandering.adapter;

import android.app.Activity;
import android.content.Context;

import com.gs.SynAntiWandering.R;
import com.gs.SynAntiWandering.adapter.base.BaseAdapter;
import com.gs.SynAntiWandering.adapter.base.BaseViewHolder;
import com.gs.SynAntiWandering.db.dto.MemberDto;
import com.gs.SynAntiWandering.util.OKHttpUtil;

import java.util.List;


public class MemberAdapter extends BaseAdapter<MemberDto> {

    private Activity activity;

    public MemberAdapter(Activity activity, Context context, List<MemberDto> mDatas, int layoutId) {
        super(context, mDatas, layoutId);
        this.activity = activity;
    }

    @Override
    public void convert(BaseViewHolder holder, MemberDto item, final int position) {
        holder.setPersonImageResource(activity, R.id.iv_photo, OKHttpUtil.IMG_URL+item.getPhoto());
        String cnName = item.getCnName() == null ? "" : item.getCnName();
        String enName = item.getEnName() == null ? "" : item.getEnName();
        holder.setText(R.id.tv_name, context.getString(R.string.member_name, cnName, enName));
        holder.setText(R.id.tv_cardNo, item.getCardNo() == null ? "" : item.getCardNo()+"");
        String floor = "";
        if (item.getFloor() != null) {
            floor = item.getFloor().getName();
        }
        String room = item.getRoomNum() == null ? "" : item.getRoomNum();
        String bed = item.getBedNum() == null ? "" : item.getBedNum();
        holder.setText(R.id.tv_room, context.getString(R.string.room_info, floor, room, bed));
        if (item.getMemberType() != null) {
            holder.setText(R.id.tv_type, item.getMemberType().getName());
        }

    }
}
